package com.collection;

import java.util.Objects;
import java.util.Set;

/**
 * Created by houjinxin on 16/4/26.
 */
public class MyHashMap {

    private static final int defaultSize = 16;
    private Entry[] objects;
    private int size;

    public MyHashMap() {
        objects = new Entry[defaultSize];
        this.size = defaultSize;
    }

    public MyHashMap(int size) {
        objects = new Entry[size];
        this.size = size;
    }


    public void put(Object key, Object value) {

    }

    public Object get(Object key) {
        return null;
    }

    public void remove(Object key) {

    }

    public void removeAll() {
        objects = null;
    }

    public int size() {
        return this.size;
    }

    public Set<Object> keySet(){
        return null;
    }

    public Set<Object> values(){
        return null;
    }

    public Set<Entry> entrySet() {
        return null;
    }

    public static class Entry {
        int hash;
        Object key;
        Object value;
        Entry next;

        public Entry(int hash, Object key, Object value, Entry next) {
            this.hash = hash;
            this.key = key;
            this.value = value;
            this.next = next;
        }

        public Object getKey() {
            return key;
        }

        public void setKey(Object key) {
            this.key = key;
        }

        public Object getValue() {
            return value;
        }

        public void setValue(Object value) {
            this.value = value;
        }

        public Entry getNext() {
            return next;
        }

        public void setNext(Entry next) {
            this.next = next;
        }

        @Override
        public int hashCode() {
            return Objects.hashCode(key) ^ Objects.hashCode(value);
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            } else if (obj instanceof Entry) {
                Entry entry = (Entry) obj;
                if (Objects.equals(key, entry.getKey()) &&
                        Objects.equals(value, entry.getValue())) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }
    }
}
